package com.javasm.aspectj.aspect;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @Author：longjinyi
 * @Version：1.0
 * @Date：2021/12/15-8:41
 * @Since:jdk1.8
 * @Description:
 */
public class MyAspect implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {

        //对拦截到的方法进行增强
        Object proceed = null;
        try {
            System.out.println("开启事务");
            // methodInvocation.proceed();拦截到的方法不做任何增强
            proceed = methodInvocation.proceed();//执行被代理对象(目标对象)的方法：不做任何增强。但是在方法的前后做增强
            System.out.println("提交事务");
        } catch (Exception e) {
            System.out.println("出现异常");
        }finally {
            System.out.println("释放资源");
        }
        return proceed;
    }
}
